• Nolan Lawson discusses a performance issue encountered with the emoji-picker-element, particularly when handling a large number of custom emojis on a Mastodon instance. The challenge arose from the presence of nearly 20,000 custom emojis, which resulted in a significant number of DOM elements and caused the page to freeze and stutter during rendering. Each emoji was represented by a button and an image, leading to a total of around 40,000 elements. Despite using lazy loading for images, the sheer volume of elements made rendering slow, far exceeding the recommended limit of 1,400 elements by Lighthouse. Lawson initially considered implementing virtualization to manage the large number of elements but was hesitant due to its complexity and potential accessibility implications. However, he later realized that CSS content-visibility could provide a simpler solution. This CSS feature allows certain parts of the DOM to be "hidden" from layout and paint processes, improving performance without affecting accessibility or requiring virtualization. To implement this, Lawson used the emoji categories as a sizing reference, applying CSS custom properties to estimate the size of off-screen elements. This approach allowed the browser to reserve space for these elements without rendering them immediately, which significantly reduced layout costs. After testing, he found that the initial performance improvements were modest, but further investigation revealed that the lazy loading of images was still causing performance issues. By removing the lazy loading attribute and instead using CSS to set background images on pseudo-elements, Lawson was able to halve the number of DOM elements and create a more efficient loading mechanism. This change resulted in a substantial performance boost, with improvements of around 40% in Chrome and 35% in Firefox. Ultimately, the emoji picker’s performance improved from approximately three seconds to just over one second, making it much more usable. Despite the success of this solution, Lawson expressed concerns about scalability for even larger instances with more emojis. He acknowledged that while content-visibility provided a good interim solution, a virtualized list would still be the optimal approach for maximum performance. He remains hopeful for future developments in web standards that might introduce built-in virtual list capabilities, but for now, he finds content-visibility to be a practical alternative that balances performance and accessibility.

  • Cloudflare has introduced a new feature called Speed Brain, designed to significantly enhance web page loading times by up to 45%. This innovation is particularly relevant in an era where performance is crucial for user engagement and retention. Speed Brain leverages the Speculation Rules API to anticipate user navigation patterns, allowing it to prefetch content before users actually click on links. This proactive approach means that when a user decides to navigate to a new page, the content is already cached in their browser, resulting in near-instant loading times. The initial implementation of Speed Brain focuses on prefetching static content when a user initiates a touch or click event. Future updates will introduce more aggressive models, including prerendering, which will not only fetch but also render the next page in advance. This capability aims to eliminate latency for static websites without requiring any configuration from users. To illustrate its effectiveness, consider an e-commerce site where users typically navigate from a parent category to specific items. By analyzing global request logs, Speed Brain can predict that a user viewing "Men's Clothes" is likely to click on "Shirts." Consequently, it begins delivering the relevant static content, such as images, even before the user clicks the link, resulting in an instantaneous page load when the click occurs. Early tests have shown that this method can reduce the Largest Contentful Paint (LCP) metric by up to 75%, which measures how quickly the largest visible element on a page loads. Speed Brain is available to all Cloudflare plan types at no additional cost. Users can enable it easily through their dashboard or API. For free domains, Speed Brain is activated by default, while Pro, Business, and Enterprise users need to enable it manually. Additionally, enabling Real User Measurements (RUM) is recommended to track performance improvements and optimize prefetching rules based on actual user behavior. Understanding how browsers load content is essential to appreciate the significance of Speed Brain. When a user navigates to a web page, the browser must establish a secure connection, send an HTTP request, and retrieve the necessary resources, including HTML, CSS, and JavaScript. This process can introduce delays, especially as users navigate through multiple pages. Speed Brain aims to mitigate these delays by prefetching and prerendering content based on user interactions, thus providing a smoother browsing experience. Historically, prefetching techniques have existed but often lacked the necessary data insights and flexibility. Previous methods required developers to manually specify which resources to prefetch, leading to inefficiencies. Cloudflare's Speed Brain addresses these limitations by dynamically determining prefetch candidates based on real-time user interactions, rather than relying on static configurations. The implementation of Speed Brain is made possible through the Speculation Rules API, which allows the browser to receive guidance on when to prefetch content. This approach minimizes the risk of stale configurations and incorrect prefetching, ensuring that resources are only fetched when they are likely to be needed. The initial conservative model prioritizes safety and efficiency, with plans to explore more aggressive settings in the future. Cloudflare's extensive global network enhances the effectiveness of Speed Brain by serving prefetched content directly from its CDN cache, significantly reducing latency. The feature is currently supported in Chromium-based browsers, with plans for broader adoption as the web community standardizes the Speculation Rules API. As Speed Brain continues to evolve, Cloudflare is exploring the integration of machine learning to refine its predictive capabilities further. This will enable more accurate prefetching based on user behavior, enhancing performance while maintaining user privacy. Future developments may also include prerendering capabilities and the potential bundling of Speed Brain with other performance-enhancing features like Argo Smart Routing. In conclusion, Speed Brain represents a significant advancement in web performance optimization, providing users with faster loading times and a more seamless browsing experience. Cloudflare encourages users to enable this feature and utilize RUM tools to monitor its impact on their website's performance.